package com.github.catvod.spider.merge;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HH {
  private static final String[] V0;
  
  private static final String[] h = new String[] { ",", ">", "+", "~", " " };
  
  private static final Pattern j;
  
  private static final Pattern q;
  
  private final List<ms> BQ = new ArrayList<ms>();
  
  private final KY I;
  
  private final String oC;
  
  static {
    V0 = new String[] { "=", "!=", "^=", "$=", "*=", "~=" };
    j = Pattern.compile("(([+-])?(\\d+)?)n(\\s*([+-])?\\s*\\d+)?", 2);
    q = Pattern.compile("([+-])?(\\d+)");
  }
  
  private HH(String paramString) {
    R2.BQ(paramString);
    paramString = paramString.trim();
    this.oC = paramString;
    this.I = new KY(paramString);
  }
  
  private int BQ() {
    String str = this.I.V0(")").trim();
    R2.q(ZG.W(str), "Index must be numeric");
    return Integer.parseInt(str);
  }
  
  private void F8() {
    if (this.I.oq("#")) {
      q();
    } else if (this.I.oq(".")) {
      j();
    } else {
      if (this.I.i4() || this.I.F8("*|")) {
        I();
        return;
      } 
      if (this.I.F8("[")) {
        V0();
      } else if (this.I.oq("*")) {
        h();
      } else if (this.I.oq(":lt(")) {
        i4();
      } else if (this.I.oq(":gt(")) {
        iU();
      } else if (this.I.oq(":eq(")) {
        n();
      } else if (this.I.F8(":has(")) {
        t();
      } else if (this.I.F8(":contains(")) {
        u(false);
      } else if (this.I.F8(":containsOwn(")) {
        u(true);
      } else if (this.I.F8(":containsData(")) {
        Qy();
      } else if (this.I.F8(":matches(")) {
        y(false);
      } else if (this.I.F8(":matchesOwn(")) {
        y(true);
      } else if (this.I.F8(":not(")) {
        PD();
      } else if (this.I.oq(":nth-child(")) {
        oq(false, false);
      } else if (this.I.oq(":nth-last-child(")) {
        oq(true, false);
      } else if (this.I.oq(":nth-of-type(")) {
        oq(false, true);
      } else if (this.I.oq(":nth-last-of-type(")) {
        oq(true, true);
      } else if (this.I.oq(":first-child")) {
        this.BQ.add(new ms.cy());
      } else if (this.I.oq(":last-child")) {
        this.BQ.add(new ms.EE());
      } else if (this.I.oq(":first-of-type")) {
        this.BQ.add(new ms.z());
      } else if (this.I.oq(":last-of-type")) {
        this.BQ.add(new ms.sy());
      } else if (this.I.oq(":only-child")) {
        this.BQ.add(new ms.Sf());
      } else if (this.I.oq(":only-of-type")) {
        this.BQ.add(new ms.pK());
      } else if (this.I.oq(":empty")) {
        this.BQ.add(new ms.A());
      } else if (this.I.oq(":root")) {
        this.BQ.add(new ms.s());
      } else if (this.I.oq(":matchText")) {
        this.BQ.add(new ms.uJ());
      } else {
        throw new CR.Tw("Could not parse query '%s': unexpected token at '%s'", new Object[] { this.oC, this.I.y() });
      } 
    } 
  }
  
  public static ms GM(String paramString) {
    try {
      HH hH = new HH();
      this(paramString);
      return hH.j5();
    } catch (IllegalArgumentException illegalArgumentException) {
      throw new CR.Tw(illegalArgumentException.getMessage(), new Object[0]);
    } 
  }
  
  private void I() {
    String str = AR.V0(this.I.oC());
    R2.BQ(str);
    if (str.startsWith("*|")) {
      this.BQ.add(new v6.yh(new ms[] { new ms.aF(str), new ms.JL(str.replace("*|", ":")) }));
    } else {
      String str1 = str;
      if (str.contains("|"))
        str1 = str.replace("|", ":"); 
      this.BQ.add(new ms.aF(str1));
    } 
  }
  
  private void PD() {
    this.I.q(":not");
    String str = this.I.h('(', ')');
    R2.W(str, ":not(selector) subselect must not be empty");
    this.BQ.add(new Yj.d(GM(str)));
  }
  
  private void Qy() {
    this.I.q(":containsData");
    String str = KY.j5(this.I.h('(', ')'));
    R2.W(str, ":containsData(text) query must not be empty");
    this.BQ.add(new ms.H(str));
  }
  
  private void V0() {
    KY kY = new KY(this.I.h('[', ']'));
    String str = kY.W(V0);
    R2.BQ(str);
    kY.u();
    if (kY.Qy()) {
      if (str.startsWith("^")) {
        this.BQ.add(new ms.d(str.substring(1)));
      } else {
        this.BQ.add(new ms.yh(str));
      } 
    } else if (kY.oq("=")) {
      this.BQ.add(new ms.c(str, kY.y()));
    } else if (kY.oq("!=")) {
      this.BQ.add(new ms.j(str, kY.y()));
    } else if (kY.oq("^=")) {
      this.BQ.add(new ms.i(str, kY.y()));
    } else if (kY.oq("$=")) {
      this.BQ.add(new ms.qM(str, kY.y()));
    } else if (kY.oq("*=")) {
      this.BQ.add(new ms.W(str, kY.y()));
    } else {
      if (kY.oq("~=")) {
        this.BQ.add(new ms.x(str, Pattern.compile(kY.y())));
        return;
      } 
      throw new CR.Tw("Could not parse attribute query '%s': unexpected token at '%s'", new Object[] { this.oC, kY.y() });
    } 
  }
  
  private String W() {
    StringBuilder stringBuilder = ZG.V0();
    while (!this.I.Qy()) {
      if (this.I.F8("(")) {
        stringBuilder.append("(");
        stringBuilder.append(this.I.h('(', ')'));
        stringBuilder.append(")");
        continue;
      } 
      if (this.I.F8("[")) {
        stringBuilder.append("[");
        stringBuilder.append(this.I.h('[', ']'));
        stringBuilder.append("]");
        continue;
      } 
      if (this.I.n(h))
        break; 
      stringBuilder.append(this.I.j());
    } 
    return ZG.t(stringBuilder);
  }
  
  private void h() {
    this.BQ.add(new ms.Tw());
  }
  
  private void i4() {
    this.BQ.add(new ms.TL(BQ()));
  }
  
  private void iU() {
    this.BQ.add(new ms.E(BQ()));
  }
  
  private void j() {
    String str = this.I.I();
    R2.BQ(str);
    this.BQ.add(new ms.kb(str.trim()));
  }
  
  private void n() {
    this.BQ.add(new ms.BU(BQ()));
  }
  
  private void oC(char paramChar) {
    // Byte code:
    //   0: aload_0
    //   1: getfield I : Lcom/github/catvod/spider/merge/KY;
    //   4: invokevirtual u : ()Z
    //   7: pop
    //   8: aload_0
    //   9: invokespecial W : ()Ljava/lang/String;
    //   12: invokestatic GM : (Ljava/lang/String;)Lcom/github/catvod/spider/merge/ms;
    //   15: astore #6
    //   17: aload_0
    //   18: getfield BQ : Ljava/util/List;
    //   21: invokeinterface size : ()I
    //   26: iconst_1
    //   27: if_icmpne -> 79
    //   30: aload_0
    //   31: getfield BQ : Ljava/util/List;
    //   34: iconst_0
    //   35: invokeinterface get : (I)Ljava/lang/Object;
    //   40: checkcast com/github/catvod/spider/merge/ms
    //   43: astore #4
    //   45: aload #4
    //   47: astore_3
    //   48: aload #4
    //   50: instanceof com/github/catvod/spider/merge/v6$yh
    //   53: ifeq -> 91
    //   56: aload #4
    //   58: astore_3
    //   59: iload_1
    //   60: bipush #44
    //   62: if_icmpeq -> 91
    //   65: aload #4
    //   67: checkcast com/github/catvod/spider/merge/v6$yh
    //   70: invokevirtual j : ()Lcom/github/catvod/spider/merge/ms;
    //   73: astore_3
    //   74: iconst_1
    //   75: istore_2
    //   76: goto -> 96
    //   79: new com/github/catvod/spider/merge/v6$Tw
    //   82: dup
    //   83: aload_0
    //   84: getfield BQ : Ljava/util/List;
    //   87: invokespecial <init> : (Ljava/util/Collection;)V
    //   90: astore_3
    //   91: aload_3
    //   92: astore #4
    //   94: iconst_0
    //   95: istore_2
    //   96: aload_0
    //   97: getfield BQ : Ljava/util/List;
    //   100: invokeinterface clear : ()V
    //   105: iload_1
    //   106: bipush #32
    //   108: if_icmpeq -> 308
    //   111: iload_1
    //   112: bipush #62
    //   114: if_icmpeq -> 277
    //   117: iload_1
    //   118: bipush #126
    //   120: if_icmpeq -> 246
    //   123: iload_1
    //   124: bipush #43
    //   126: if_icmpeq -> 215
    //   129: iload_1
    //   130: bipush #44
    //   132: if_icmpne -> 177
    //   135: aload_3
    //   136: instanceof com/github/catvod/spider/merge/v6$yh
    //   139: ifeq -> 150
    //   142: aload_3
    //   143: checkcast com/github/catvod/spider/merge/v6$yh
    //   146: astore_3
    //   147: goto -> 168
    //   150: new com/github/catvod/spider/merge/v6$yh
    //   153: dup
    //   154: invokespecial <init> : ()V
    //   157: astore #5
    //   159: aload #5
    //   161: aload_3
    //   162: invokevirtual I : (Lcom/github/catvod/spider/merge/ms;)V
    //   165: aload #5
    //   167: astore_3
    //   168: aload_3
    //   169: aload #6
    //   171: invokevirtual I : (Lcom/github/catvod/spider/merge/ms;)V
    //   174: goto -> 336
    //   177: new java/lang/StringBuilder
    //   180: dup
    //   181: invokespecial <init> : ()V
    //   184: astore_3
    //   185: aload_3
    //   186: ldc_w 'Unknown combinator: '
    //   189: invokevirtual append : (Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   192: pop
    //   193: aload_3
    //   194: iload_1
    //   195: invokevirtual append : (C)Ljava/lang/StringBuilder;
    //   198: pop
    //   199: new com/github/catvod/spider/merge/CR$Tw
    //   202: dup
    //   203: aload_3
    //   204: invokevirtual toString : ()Ljava/lang/String;
    //   207: iconst_0
    //   208: anewarray java/lang/Object
    //   211: invokespecial <init> : (Ljava/lang/String;[Ljava/lang/Object;)V
    //   214: athrow
    //   215: new com/github/catvod/spider/merge/v6$Tw
    //   218: dup
    //   219: iconst_2
    //   220: anewarray com/github/catvod/spider/merge/ms
    //   223: dup
    //   224: iconst_0
    //   225: new com/github/catvod/spider/merge/Yj$HA
    //   228: dup
    //   229: aload_3
    //   230: invokespecial <init> : (Lcom/github/catvod/spider/merge/ms;)V
    //   233: aastore
    //   234: dup
    //   235: iconst_1
    //   236: aload #6
    //   238: aastore
    //   239: invokespecial <init> : ([Lcom/github/catvod/spider/merge/ms;)V
    //   242: astore_3
    //   243: goto -> 336
    //   246: new com/github/catvod/spider/merge/v6$Tw
    //   249: dup
    //   250: iconst_2
    //   251: anewarray com/github/catvod/spider/merge/ms
    //   254: dup
    //   255: iconst_0
    //   256: new com/github/catvod/spider/merge/Yj$W
    //   259: dup
    //   260: aload_3
    //   261: invokespecial <init> : (Lcom/github/catvod/spider/merge/ms;)V
    //   264: aastore
    //   265: dup
    //   266: iconst_1
    //   267: aload #6
    //   269: aastore
    //   270: invokespecial <init> : ([Lcom/github/catvod/spider/merge/ms;)V
    //   273: astore_3
    //   274: goto -> 336
    //   277: new com/github/catvod/spider/merge/v6$Tw
    //   280: dup
    //   281: iconst_2
    //   282: anewarray com/github/catvod/spider/merge/ms
    //   285: dup
    //   286: iconst_0
    //   287: new com/github/catvod/spider/merge/Yj$yh
    //   290: dup
    //   291: aload_3
    //   292: invokespecial <init> : (Lcom/github/catvod/spider/merge/ms;)V
    //   295: aastore
    //   296: dup
    //   297: iconst_1
    //   298: aload #6
    //   300: aastore
    //   301: invokespecial <init> : ([Lcom/github/catvod/spider/merge/ms;)V
    //   304: astore_3
    //   305: goto -> 336
    //   308: new com/github/catvod/spider/merge/v6$Tw
    //   311: dup
    //   312: iconst_2
    //   313: anewarray com/github/catvod/spider/merge/ms
    //   316: dup
    //   317: iconst_0
    //   318: new com/github/catvod/spider/merge/Yj$c
    //   321: dup
    //   322: aload_3
    //   323: invokespecial <init> : (Lcom/github/catvod/spider/merge/ms;)V
    //   326: aastore
    //   327: dup
    //   328: iconst_1
    //   329: aload #6
    //   331: aastore
    //   332: invokespecial <init> : ([Lcom/github/catvod/spider/merge/ms;)V
    //   335: astore_3
    //   336: iload_2
    //   337: ifeq -> 352
    //   340: aload #4
    //   342: checkcast com/github/catvod/spider/merge/v6$yh
    //   345: aload_3
    //   346: invokevirtual V0 : (Lcom/github/catvod/spider/merge/ms;)V
    //   349: goto -> 355
    //   352: aload_3
    //   353: astore #4
    //   355: aload_0
    //   356: getfield BQ : Ljava/util/List;
    //   359: aload #4
    //   361: invokeinterface add : (Ljava/lang/Object;)Z
    //   366: pop
    //   367: return
  }
  
  private void oq(boolean paramBoolean1, boolean paramBoolean2) {
    String str = AR.V0(this.I.V0(")"));
    Matcher matcher1 = j.matcher(str);
    Matcher matcher2 = q.matcher(str);
    boolean bool = "odd".equals(str);
    int j = 2;
    byte b = 0;
    int i = 0;
    if (bool) {
      i = 1;
    } else if ("even".equals(str)) {
      i = b;
    } else if (matcher1.matches()) {
      if (matcher1.group(3) != null) {
        j = Integer.parseInt(matcher1.group(1).replaceFirst("^\\+", ""));
      } else {
        j = 1;
      } 
      if (matcher1.group(4) != null)
        i = Integer.parseInt(matcher1.group(4).replaceFirst("^\\+", "")); 
    } else if (matcher2.matches()) {
      i = Integer.parseInt(matcher2.group().replaceFirst("^\\+", ""));
      j = 0;
    } else {
      throw new CR.Tw("Could not parse nth-index '%s': unexpected format", new Object[] { str });
    } 
    if (paramBoolean2) {
      if (paramBoolean1) {
        this.BQ.add(new ms.u(j, i));
      } else {
        this.BQ.add(new ms.lW(j, i));
      } 
    } else if (paramBoolean1) {
      this.BQ.add(new ms.jH(j, i));
    } else {
      this.BQ.add(new ms.V(j, i));
    } 
  }
  
  private void q() {
    String str = this.I.I();
    R2.BQ(str);
    this.BQ.add(new ms.RN(str));
  }
  
  private void t() {
    this.I.q(":has");
    String str = this.I.h('(', ')');
    R2.W(str, ":has(el) subselect must not be empty");
    this.BQ.add(new Yj.Tw(GM(str)));
  }
  
  private void u(boolean paramBoolean) {
    KY kY = this.I;
    if (paramBoolean) {
      str = ":containsOwn";
    } else {
      str = ":contains";
    } 
    kY.q(str);
    String str = KY.j5(this.I.h('(', ')'));
    R2.W(str, ":contains(text) query must not be empty");
    if (paramBoolean) {
      this.BQ.add(new ms.q(str));
    } else {
      this.BQ.add(new ms.p(str));
    } 
  }
  
  private void y(boolean paramBoolean) {
    KY kY = this.I;
    if (paramBoolean) {
      str = ":matchesOwn";
    } else {
      str = ":matches";
    } 
    kY.q(str);
    String str = this.I.h('(', ')');
    R2.W(str, ":matches(regex) query must not be empty");
    if (paramBoolean) {
      this.BQ.add(new ms.jP(Pattern.compile(str)));
    } else {
      this.BQ.add(new ms.oe(Pattern.compile(str)));
    } 
  }
  
  ms j5() {
    this.I.u();
    if (this.I.n(h)) {
      this.BQ.add(new Yj.qM());
      oC(this.I.j());
    } else {
      F8();
    } 
    while (!this.I.Qy()) {
      boolean bool = this.I.u();
      if (this.I.n(h)) {
        oC(this.I.j());
        continue;
      } 
      if (bool) {
        oC(' ');
        continue;
      } 
      F8();
    } 
    return (this.BQ.size() == 1) ? this.BQ.get(0) : new v6.Tw(this.BQ);
  }
  
  public String toString() {
    return this.oC;
  }
}


/* Location:              /Users/hetaiyi/Desktop/my/tech/java/study/aa/temp/temp.jar!/com/github/catvod/spider/merge/HH.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */